#include <SoftwareSerial.h>
#include "DHT.h"

SoftwareSerial mySerial(2, 3); // RX, TX
#define BUF_LEN 50
char SEND_BUF[BUF_LEN];
#define Msg "{\"Temperature\": \"%s\", \"Humidity\": \"%s\"}"

#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
float Temp, Humi;

void setup() {
  Serial.begin(115200);
  while (!Serial) {;}

  mySerial.begin(57600);
  dht.begin();

}

void loop() { // run over and over
  static unsigned long now = millis();
  if (millis() - now >= 10000) {
    now = millis();
    Get_Temp_Humi();
    
    snprintf(SEND_BUF, BUF_LEN, Msg, String(Temp).c_str(), String(Humi).c_str());
    mySerial.write(SEND_BUF);
  }
}

void Get_Temp_Humi() {
  Temp = dht.readTemperature();
  Humi = dht.readHumidity();

  if (isnan(Humi) || isnan(Temp)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
}